package com.cy.pj.sys.service.Impl;


import com.cy.pj.sys.dao.UserDao;
import com.cy.pj.sys.pojo.User;
import com.cy.pj.sys.service.UserService;
import com.cy.pj.sys.util.MD5Util;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service

public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User login(String userName, String password) {
        //创建shiro的 Subject对象进行登录效验
        Subject subject= SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(userName, MD5Util.md5(password));
        subject.login(token);


        //返回用户信息
        User user = userDao.getUserByName(userName);
        user.setPassword(password);
        return user;
    }

    @Override
    public boolean updatePassword(int id, String password) {

        return userDao.updatePassword(id, MD5Util.md5(password)) > 0;
    }
}
